/**
 * 添加-初始化数据
 * @returns
 */
function addLoad(pid){
	if(pid==="-1"){
		pid = "0";
	}
	$("#b_pid").val(pid);
}

/**
 * 修改-初始化数据
 * @returns
 */
function updateLoad(id){
    $$.ajax({
        url:"/rest/IotDeviceCatalogBusiness/query",
        suiteCode:"iot",
        data: {
            id: id
        },
        success: function(data){
            $("#b_id").val(data.id);
            $("#b_pid").val(data.pid);
            $("#b_catalogCode").val(data.catalogCode);
            $("#b_catalogName").val(data.catalogName);
            var status = data.status;
            if(status==1){
            	$('#in-use').attr('checked', 'checked');
            }else{
            	$('#not-in-use').attr('checked', 'checked');
            }
            $("#b_rowSort").val(data.rowSort);
            $("#b_remarks").val(data.remarks);
        }
    });
}

/**
 * 添加校验
 * @returns
 */
function addvalidate() {
    $("#deviceCatalogForm").validate({
        rules: {
            b_catalogCode: {
            	required: true,
                rangelength: [1,30]
            },
            b_catalogName: {
            	required: true,
                rangelength: [1,30]
            },
            b_rowSort:{
                required: true,
                range: [1,9999999]
            },
            b_remarks:{
                maxlength: 250
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errortips",
        success: 'valid',
        messages: {
            b_catalogCode: {
            	required: "(必填)",
                rangelength:"(类别编码必须是{0}到{1}个字符)"
            },
            b_catalogName: {
            	required: "(必填)",
                rangelength:"(类别名称必须是{0}到{1}个字符)"
            },
            b_rowSort: {
                required: "(必填)",
                range:"(排序值必须在{0}和{1}之间)"
            },
            b_remarks: {
                maxlength:"(备注不能超过250个字符)"
            }
        },
    });
}

/**
 * 验证数据
 * @returns
 */
function validForm(){
    return $('#deviceCatalogForm').valid();
}

/**
 * 提交数据
 * @returns
 */
function submitForm(){
    var param = {};
    var validFormRet;
    $$.form({
    	fname:"#deviceCatalogForm",
    	suiteCode:"iot",
    	async:false,
        able:function(){
            validFormRet=false;
        },
        checkForm: validForm,
        success: function () {
            validFormRet= true;
        }
    });
    return validFormRet;
}

$(function () {
	$('#b_catalogCode').focus();
	addvalidate();
});

